﻿using System.Collections.Generic;
using System.Xml;
using IURIP;

namespace URIP.Core
{
    public abstract class BaseTemplate : ITemplate
    {
        public BaseTemplate(ITarget target, ITemplate parentTemplate)
        {
            m_target = target;
            m_parentTemplate = parentTemplate;
        }

        protected ITemplate m_parentTemplate = null;
        protected LinkedList<ITemplate> m_childrenTemplates = new LinkedList<ITemplate>();
        protected ITarget m_target = null;

        public IProcessTemplate ProcessTemplate
        {
            get
            {
                if (this is IProcessTemplate)
                {
                    return (IProcessTemplate)this;
                }
                else
                {
                    return ParentTemplate == null ? null : ParentTemplate.ProcessTemplate;
                }
            }
        }

        public IActionTemplate ActionTemplate
        {
            get
            {
                if (this is IActionTemplate)
                {
                    return (IActionTemplate)this;
                }
                else
                {
                    return ParentTemplate == null ? null : ParentTemplate.ActionTemplate;
                }
            }
        }
        public ITemplate ParentTemplate
        {
            get { return m_parentTemplate; }
        }
        public LinkedList<ITemplate> ChildrenTemplates
        {
            get { return m_childrenTemplates; }
        }
        public ITask Task
        {
            get {return m_target.Task; }
        }
        public ITarget Target
        {
            get { return m_target; }
        }
        public bool HasBreakPoint
        {
            get;
            set;
        }

        public abstract IRunable CreateRunable(IRunable parentRunable);
        public abstract void InitByConfiguration(XmlNode node);
    }
}
